import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { Iwe7FormBuilderService } from "../iwe7-form-builder.service";

@Component({
  selector: "data-list",
  templateUrl: "./data-list.component.html",
  styleUrls: ["./data-list.component.scss"]
})
export class DataListComponent implements OnInit {
  list: any[] = [];
  fields: any[] = [];
  id: any = 0;
  constructor(
    public route: ActivatedRoute,
    public router: Router,
    public fb: Iwe7FormBuilderService
  ) {
    this.route.queryParams.subscribe(res => {
      this.id = res.id;
    });
  }

  ngOnInit() {
    this.fb.getData(this.id).subscribe((res: any) => {
      this.list = res.list;
      this.fields = res.fields;
    });
  }

  addData() {
    this.router.navigate(["/formBuilder/createTable"], {
      queryParams: {
        id: this.id
      }
    });
  }
}
